/**
 * @param {number} n
 * @return {number}
 */
var monotoneIncreasingDigits = function (n) {
  let nums = String(n).split('')
  let m = nums.length
  let flag = m
  for (let i = m - 1; i > 0; i--) {
    if (nums[i] < nums[i - 1]) {
      nums[i - 1] = nums[i - 1] - 1
      flag = i
    }
  }
  console.log(flag)
  for (let i = flag; i < m; i++) {
    nums[flag] = 9
  }
  console.log(nums)
  return nums.join('')
};
console.log(monotoneIncreasingDigits(100));